<?
	/* Se asegura que el archivo es incluido por el index */
		defined( 'LOAD_MODULE_ACTION' ) or die( 'No esta permitido el acceso directo a ' . __FILE__ );
	/* Cuando se hace el include del archivo automaticamente crea un objeto y lo guarda en una variable temporal */
		$this->oTmpObject = new Accion_lst( $this );

	class Accion_lst extends Lst
	{
	function Accion_lst( &$oModule )
		{
			$this->Lst( $oModule );
			$this->cField = 'ncAccion[]'; 
		}
	function setLevel()
		{
			switch ( $this->getOptionView() )
			{
				case 'E':
				case 'L':
					$this->aShowColumns = array( 'Nombre' , 'SubModulo', 'Tipo');
					break;
			}
		}

	function makeColumn( &$aRow, $cName )
	{
		switch ( $cName )
		{
			case 'NombreDefine':
				$cReturn =  strtoupper(str_replace( ' ', '_' ,$aRow['cNombre']));
				break;
			case 'KeyLookUp':
				$cReturn = $aRow['ncAccion'];
				break;
		}
		return $cReturn;
	}
	function initialize()
	{
		$this->oFiltro = $this->oModule->loadClass( 'accion_frm' );
		$this->aFields[ncAccion] = getParam('ncAccionPermiso');
		$this->aFields = array_merge ( (array)$this->aFields,  (array)$this->oFiltro->getFieldArray() );
		// Pone el tab de los Modulos
		$oTab =& $this->setIndex( INDEX_USER, TAB_TOP, 'cPathModule' , true);
		initializeTabModulo( $oTab );
		$this->aFields['cPathModule']  = $oTab->getValue();
		$this->oDatabase = openMetadataDB ( $this->aFields['cPathModule'] );
		if ( $this->aFields['cPathModule'] ) 
		{
			$oTab =& $this->setIndex( INDEX_USER, TAB_BOTTOM, 'ncSubModulo' );
			$oTab->setMatrix( $this->oDatabase->getMatrix("SELECT ncSubModulo, cdSubModulo FROM stSubModulo") );
		}
		$this->setTitle ( "Acciones" );
		$this->setSummary( "Esta tabla contiene el listado de Acciones" );
		$this->addColumn ( 'Codigo', 'ncAccion', true );
		$this->addColumnAction ( 'Nombre', VER_ACCION, 'ncAccion', 'cdAccion' );
		$this->addColumn ( 'SubModulo', 'cdSubModulo', true );
		$this->addColumn ( 'Tipo', 'cdTipoAccion', true );
		$this->addColumn ( 'NombreDefine' );
		$this->oPaging->setOrderBy( 'ncAccion' , false);
	}
	function query()
		{
			// Arma el Query
				$cSql = "SELECT Act.ncAccion, Act.cdAccion, Act.cNombre, Act.cIcono, Ti.ncTipoAccion, Ti.cdTipoAccion,Sub.cdSubModulo, Sub.ncSubModulo
												FROM stAccion as Act
												LEFT JOIN stSubModulo as Sub
													ON Sub.ncSubModulo = Act.ncSubModulo
												JOIN scTipoAccion as Ti
													On Ti.ncTipoAccion = Act.ncTipoAccion";
			// Arma el Filtro de la Consulta
				$this->oFiltro->setDefaultSearchField( "cdAccion" );
				$aFiltro = $this->oFiltro->getFilterdArray() ;
				unset($aFiltro[cPathModule]);
				$this->oWhere->addArray ( $aFiltro, 'Act' );
				if ( getParam('bSinActores') ) $this->oWhere->addExpression ( "Act.ncAccion", " Act.ncAccion NOT IN ( SELECT ncAccion FROM stPermiso ) " );
				if ( getParam('bSinClases') ) $this->oWhere->addExpression ( "Act.ncAccion", "Act.ncAccion NOT IN ( SELECT ncAccion FROM stAccionClase ) " );
			return $cSql . $this->oWhere->make();
		}
	function makeListActions()
		{
			$cParametroRegistro =  $this->getFieldString();
			$this->addListAction ( CONSULTAR_PERMISOS );
			$this->addListAction ( AGREGAR_ACCION, $cParametroRegistro, 'I' );
			$this->addListAction ( GENERAR_METADATA );
			$this->addListAction ( CONSULTAR_SUBMODULOS );
			$this->addSelectionAction ( COPIAR_ACCION ,  "cPathModule=" . $this->aFields['cPathModule'] );
			$this->addSelectionAction ( CAMBIAR_SUBMODULO_ACCION ,  "cPathModule=" . $this->aFields['cPathModule'] );
			$this->addSelectionAction ( ELIMINAR_ACCION ,  "cPathModule=" . $this->aFields['cPathModule'] );
		}
	function makeRowActions( $aRow )
		{
			$cParametroRegistro =  "cPathModule=" . $this->aFields['cPathModule'] . "&amp;ncAccion=" . $aRow["ncAccion"];
			$this->addRowAction ( DUPLICAR_ACCION, $cParametroRegistro );
			$this->addRowAction ( MODIFICAR_ACCION, $cParametroRegistro );
			$this->addRowAction ( ELIMINAR_ACCION ,  $cParametroRegistro );
			$this->addRowAction ( COPIAR_ACCION ,  $cParametroRegistro );
		}
	function makeComplex ()
		{
			$oLst = $this->oModule->loadClass ( "accion_clase_lst" );
			$oLst->aFields['ncAccion'] = $this->aFields['ncAccion'];
			$oLst->setNoPaging();
			$oLst->makeDir();
		}
	}
?>